package com.example.mq;

import com.example.config.TtlQueueConfig;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 消费者
 * 监听死信队列
 * @author wuyunbin
 */
@Slf4j
@Component
public class Consumer {
    @RabbitListener(queues = TtlQueueConfig.DEAD_QUEUE_NAME)
    public void receiveMessage(Message message){
        String msg = new String(message.getBody());
        SimpleDateFormat format=new SimpleDateFormat("yyyy/MM/dd HH:mm:ss:SSS");
        log.info("当前时间：{}，收到死信队列的消息：{}", format.format(new Date()) ,msg);
    }
}

